<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="5" class="tl-left-tree">
                <!-- 树 -->
                <!-- <el-input v-model="queryTreeParam.qry_name" placeholder="根据名称筛选" @keyup.enter.native="filterTree" ref="treeSearch">
          <el-button current-node-key="" slot="append" icon="el-icon-search" @click="filterTree"></el-button>
        </el-input> -->
                <el-scrollbar ref="treeScroll">
                    <el-tree class="tl-tree" ref="tree" @node-click="nodeClick" :data="treeData" node-key="id" :expand-on-click-node="false" :default-expanded-keys="[0]" highlight-current></el-tree>
                </el-scrollbar>
            </el-col>
            <el-col :span="19" :offset="0">
                <!-- 查询 -->
                <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
                    <template slot="search">
                        <el-form-item label="页面编码" prop="code">
                            <el-input v-model="queryParam.qry_code" placeholder=""></el-input>
                        </el-form-item>
                        <el-form-item label="页面名称">
                            <el-input v-model="queryParam.qry_name" placeholder=""></el-input>
                        </el-form-item>
                    </template>
                </tl-list-search>
                <!-- 工具栏 -->
                <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayDeleteBatch="user.adminlevel===9" :isDisplayAdd="user.adminlevel===9">
                    <template slot="left-btn"> </template>
                </tl-list-toolbar>
                <div>
                    <!-- 列表选择 -->
                    <div class="table-alert-div" ref="selector">
                        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
                            <template slot="title">
                                已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
                                <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
                            </template>
                        </el-alert>
                    </div>
                    <!--表格渲染-->
                    <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
                        <el-table-column type="selection" width="55px" fixed="left"></el-table-column>
                        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
                        <el-table-column prop="code" label="页面编码" width="150px" sortable="custom" sort-by="code" align="cenleftter" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                        <el-table-column prop="name" label="页面名称" width="150px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                        <!-- <el-table-column prop="extendfield1" label="扩展字段1" width="150px" sortable="custom" sort-by="extendfield1" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield2" label="扩展字段2" width="150px" sortable="custom" sort-by="extendfield2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield3" label="扩展字段3" width="150px" sortable="custom" sort-by="extendfield3" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield4" label="扩展字段4" width="150px" sortable="custom" sort-by="extendfield4" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield5" label="扩展字段5" width="150px" sortable="custom" sort-by="extendfield5" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield6" label="扩展字段6" width="150px" sortable="custom" sort-by="extendfield6" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield7" label="扩展字段7" width="150px" sortable="custom" sort-by="extendfield7" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield8" label="扩展字段8" width="150px" sortable="custom" sort-by="extendfield8" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield9" label="扩展字段9" width="150px" sortable="custom" sort-by="extendfield9" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="extendfield10" label="扩展字段10" width="150px" sortable="custom" sort-by="extendfield10" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
                        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
                        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column> -->
                        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">

                            <el-dropdown trigger="hover">
                                <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
                                <el-dropdown-menu>
                                    <el-dropdown-item type="text" icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)">编辑</el-dropdown-item>
                                    <el-dropdown-item type="text" icon="el-icon-delete" @click.native="doDelete(scope.row.id)" v-if="user.adminlevel==9">删除</el-dropdown-item>
                                    <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
                                </el-dropdown-menu>
                            </el-dropdown>
                        </el-table-column>
                    </el-table>
                    <!-- 列表分页 -->
                    <el-row class="pagebar" ref="pager">
                        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
                    </el-row>
                    <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
    name: 'misVuePageInfo',
    mixins: [mixin_list],
    components: { tlEdit },
    data() {
        return {
            description: '前端Vue页面信息表-列表查询',
            urlPrefix: '/mis/vuePageInfo/',
            url: {
                // queryCodeList: '/mis/vuePageInfo/dataCodeList'
            },
            treeData: [],
            // 排序参数
            sorterInfo: {
                sidx: 'sortcode',
                sord: 'asc'
            },
            crurentParentPage: {}
        }
    },
    methods: {
        // 禁用表格前面的选择
        doDisableCheckBox(row, index) {
            if (row.state !== 0 && row.state !== 2) {
                return false
            } else {
                return true
            }
        },
        /** 加载树数据 */
        loadTree() {
            return getAction('/mis/vuePageInfo/queryTreeList', this.queryTreeParam).then((res) => {
                if (res.success) {
                    this.treeData = []
                    this.treeData = res.result.dataList
                    // this.parentPage 初始化
                    this.crurentParentPage = this.treeData[0]
                    this.$refs.editForm.parentPage = this.crurentParentPage
                } else {
                    this.$tap.alert(res.message, 'warning')
                }
            })
        },
        /** 单个删除数据 */
        doDelete(id) {
            if (!this.url.delete) {
                this.$tap.alert('请设置delete地址!', 'warning')
                return
            }
            this.$tap
                .confirm('确定删除页面及其字段吗？')
                .then((_) => {
                    if (!this.beforeDoDelete(id)) {
                        return
                    }
                    deleteAction(this.url.delete, { ids: id }).then((res) => {
                        if (res.success) {
                            this.$tap.message(res.message, 'success')
                            this.loadData()
                            this.afterDoDelete(id)
                        } else {
                            this.$tap.alert(res.message, 'warning')
                        }
                    })
                })
                .catch((_) => { })
        },
        /** 批量删除数据 */
        doDeleteBatch() {
            if (!this.url.delete) {
                this.$tap.alert('请设置delete地址!', 'warning')
                return
            }
            if (this.selectedRowKeys.length <= 0) {
                this.$tap.alert('请选择记录！', 'warning')
                return
            } else {
                var ids = ''
                for (var index = 0; index < this.selectedRowKeys.length; index++) {
                    if (index === this.selectedRowKeys.length - 1) {
                        ids += this.selectedRowKeys[index]
                    } else {
                        ids += this.selectedRowKeys[index] + ','
                    }
                }
                this.$tap
                    .confirm('确定删除所选的页面及其字段吗？')
                    .then((_) => {
                        if (!this.beforeDoDelete(ids)) {
                            return
                        }
                        deleteAction(this.url.deleteBatch, { ids: ids }).then((res) => {
                            if (res.success) {
                                this.$tap.message(res.message, 'success')
                                this.loadData({})
                                this.afterDoDelete(ids)
                            } else {
                                this.$tap.alert(res.message, 'warning')
                            }
                        })
                    })
                    .catch((_) => { })
            }
        },
        // 树节点点击时触发的方法
        nodeClick(clickData) {
            this.crurentParentPage = clickData
            this.$refs.editForm.parentPage = clickData
            getAction(this.urlPrefix + 'list', { qry_parentid: clickData.id }).then((res) => {
                if (res.success) {
                    this.datas = []
                    this.datas = res.result.dataList
                } else {
                    this.$tap.alert(res.message, 'warning')
                }
            })
        }
    },
    created() {
        this.loadTree()
    }
}
</script>

<style scoped></style>

